--精神爆发
local jingshenbaofa = fk.CreateSkill {
    name = "mcdh_jingshenbaofa"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

jingshenbaofa:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Play
    end,
    on_use = function (self, event, target, player, data)
        player:turnOver()
        player.room:setPlayerMark(player, "mcdh_jsbf-turn", 1)
        player.room:setPlayerMark(player, "@mcdh_jsbf_suits-turn", {})
    end
})

jingshenbaofa:addEffect(fk.CardUsing,{
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) and player:getMark("mcdh_jsbf-turn") > 0 then
            local mark = player:getTableMark( "@mcdh_jsbf_suits-turn")
            return data.card.suit ~= Card.NoSuit and not table.contains(mark, "log_"..data.card:getSuitString())
        else
            return false
        end
    end,
    on_use = function (self, event, target, player, data)
        local mark = player:getTableMark("@mcdh_jsbf_suits-turn")
        table.insert(mark, "log_"..data.card:getSuitString())
        player.room:setPlayerMark(player, "@mcdh_jsbf_suits-turn", mark)
        player:drawCards(1, self.name)
    end
})

jingshenbaofa:addEffect('targetmod',{
    bypass_times = function(self, player, skill, scope, card, to)
        if card and card.suit ~= Card.NoSuit and player:getMark("mcdh_jsbf-turn") > 0 then
            local mark = player:getTableMark( "@mcdh_jsbf_suits-turn")
            return not table.contains(mark, "log_"..card:getSuitString())
        end
    end,
    bypass_distances = function(self, player, skill, card, to)
        if card and card.suit ~= Card.NoSuit and player:getMark("mcdh_jsbf-turn") > 0 then
            local mark = player:getTableMark("@mcdh_jsbf_suits-turn")
            return not table.contains(mark, "log_"..card:getSuitString())
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_jingshenbaofa"] = "精神爆发",
    [":mcdh_jingshenbaofa"] = "出牌阶段开始时，你可以翻面，若如此做，本回合内你使用每种花色的第一张牌无距离和次数限制，且使用此牌时，你摸一张牌",
    ["#mcdh_jingshenbaofa_cardusing"] = "",
    ["@mcdh_jsbf_suits-turn"] = "精神爆发"
}

return jingshenbaofa